﻿using FluentValidation;
using Jupiter.Infrastructure.Domain;
using MediatR;

namespace Wips.AppService.Publisher.AgentServerPermissions.Requests
{
    /// <summary>
    /// 保存权限
    /// </summary>
    public class SaveAgentPermissionRequest : ITxRequest, IRequest<string>
    {

        /// <summary>
        /// 用户id
        /// </summary>
        public string UserId { get; set; } = "";

        /// <summary>
        /// 需要授权的服务
        /// </summary>
        public List<string> AgentServerIds { get; set; } = new List<string>();


        /// <summary>
        /// 需要授权的服务id
        /// </summary>
        public List<string> AgentServerConfigIds { get; set; } = new List<string>();
    }

    /// <summary>
    /// 校验
    /// </summary>
    public class SaveAgentPermissionRequestValidator : AbstractValidator<SaveAgentPermissionRequest>
    {
        /// <summary>
        /// 
        /// </summary>
        public SaveAgentPermissionRequestValidator()
        {
            RuleFor(p => p)
                .Must(p => p.AgentServerConfigIds.Count > 0 || p.AgentServerIds.Count > 0)
                .WithMessage("授权的服务和授权的服务器不能同时为空");

            RuleFor(p => p.UserId)
                .Must(id => !string.IsNullOrEmpty(id))
                .WithMessage("用户不能为空");
        }
    }
}
